package com.larry.rabbitmq.fifth;

import com.larry.rabbitmq.util.RabbitMQUtils;
import com.rabbitmq.client.Channel;

/**
 * @author larry
 * @Title: larry-rabbitmq
 * @Package com.larry.rabbitmq.fifth
 * @Description: 消息接收
 * @date 6/30/2110:11 AM
 */
public class ReceiveLogs02 {

    public static final String EXCHANGE_NAME = "logs";

    public static void main(String args[]) throws Exception{
        Channel channel = RabbitMQUtils.getChannel();

        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        //声明一个队列 临时队列
        String queue = channel.queueDeclare().getQueue();

        /**
         * 绑定交换机与队列
         */
        channel.queueBind(queue,EXCHANGE_NAME,"");

        //接收消息
        channel.basicConsume(queue,true,(consumerTag, message) -> {
            System.out.println("02收到的消息.....: " + message.getBody().toString());
        },consumerTag -> {});

    }
}
